package titt.io.writer.head;

import titt.head.HTTPHead;
import titt.head.Header;
import titt.io.socket.out.TITTOutputStream;
import titt.util.Bytes;

public class HeadWriterImpl implements HeadWriter {

	private TITTOutputStream out;
	
	public HeadWriterImpl(TITTOutputStream out) {
		this.out = out;
	}
	
	@Override
	public void writeHead(HTTPHead h) throws Exception {
		if(h.getStatusLine() != null)
			out.writeLine(Bytes.asBytes(h.getStatusLine()));
		for(Header he : h.getAllHeaders()) {
			out.write(Bytes.asBytes(he.getName() + ": "));
			out.writeLine(he.getByteValue());
		}
		out.writeLine();
		out.flush();
	}

}
